package com.mazaiting.classfile.constant.info;

import com.mazaiting.classfile.ClassReader;
import com.mazaiting.classfile.constant.ConstantPool;

/**
 * 表示类或者接口的符号引用
 *
 * @author mazaiting
 * @since 2021/8/11
 */
public class ConstantClassInfo extends ConstantInfo{

    /**
     * 常量池索引 无符号 u2
     * CONSTANT_Utf8_info
     */
    private int nameIndex;

    public ConstantClassInfo(ConstantPool pool) {
        super(pool);
    }

    @Override
    public void readInfo(ClassReader reader) {
        this.nameIndex = reader.readU2ToUnsignedShort();
    }

    /**
     * 获取名称
     * @return 名称
     */
    public String name() {
        return this.pool.getUtf8(this.nameIndex);
    }

    @Override
    public String toString() {
        return "ConstantClassInfo{" +
                "nameIndex=" + nameIndex +
                '}';
    }
}


















